

function Cp_values = Cp_calculator(air_mass,air_O2_mass_fraction,air_CO2_mass_fraction,air_H2O_mass_fraction)

%% constants
M_O2 = 2*16;            % Molecular Mass of O2 [g/mol]
M_CO2 = 12+2*16;        % Molecular Mass of CO2 [g/mol]
M_H2O = 18.02;          % Molar Mass of H2O [g/mol]
% Ru = 8.3144621;         % Universal Gas Constant [J/(mol.K)]
% R_O2 = Ru/M_O2*1E3;     % Specific gas constant for O2 [J/(kg.K)]
% R_CO2 = Ru/M_CO2*1E3;   % Specific gas constant for CO2 [J/(kg.K)]
% R_H2O = Ru/M_CO2*1E3;   % Specific gas constant for H2O [J/(kg.K)]

%% mass

m_O2  = air_mass  * air_O2_mass_fraction;
m_CO2  = air_mass * air_CO2_mass_fraction;
m_H2O  = air_mass * air_H2O_mass_fraction;

%% Temperature Mixing
% Copied and pasted from Andrew's "TEMPERATURE COMBINATIONS" code from
% 2013.06.09

% data: from Cengel and Boles - "Thermodynamics: an engineering approach"
% 6th ed. 2008.

% 1.    Determine the number of moles present N [mol] for each body of air

% data: p. 910. Values reported in kg/kmol, divided by 1000 to convert to
% kg/mol

% for AR
O2_N = (m_O2)*1E3/M_O2; % moles of O2 in the air
CO2_N = (m_CO2)*1E3/M_CO2; % moles of CO2 in the air
H2O_N = (m_H2O)*1E3/M_H2O; % moles of H2O in the air
air_N = O2_N + CO2_N + H2O_N;

% 2.    Determine the specific heat c_p [J/mol-K] of each body of air

% data: pp. 940 (O2), 942 (CO2), 947 (H2O). (values are reported in
% kJ/kmol-K, which is equivalent to J/mol-K).
%
% Assume: value at T ~ 298K is approximately valid across the range of
% temperatures seen in our model. This assumption will need to be
% validated.

%% old Cp values from Andrew's textbook
% c_p_O2 = 205.033; % specific heat of O2 [J/mol-K]
% c_p_CO2 = 213.685; % specific heat of CO2 [J/mol-K]
% c_p_H2O = 188.720; % specific heat of H2O [J/mol-K]

%% new Cp values from Wikipedia (http://en.wikipedia.org/wiki/Heat_capacity#Table_of_specific_heat_capacities)
c_p_O2 = 29.38; % specific heat of O2 [J/mol-K]
c_p_CO2 = 36.94; % specific heat of CO2 [J/mol-K]
c_p_H2O = 75.327; % specific heat of H2O [J/mol-K]

%% unit type 1
% specific heat of AR [J/mol-K]
if air_N == 0
    Cp = 0;
else
    Cp = (O2_N/air_N)*c_p_O2 + (CO2_N/air_N)*c_p_CO2 +...
        (H2O_N/air_N)*c_p_H2O;
end

%% unit type 2
% specific heat of AR [J/kg-K]

c_p_O2_units = c_p_O2 / (M_O2/1000);
c_p_CO2_units = c_p_CO2 / (M_CO2/1000);
c_p_H2O_units = c_p_H2O / (M_H2O/1000);

if air_N == 0
    Cp_units = 0;
else
    Cp_units = (O2_N/air_N)*c_p_O2_units + (CO2_N/air_N)*c_p_CO2_units +...
        (H2O_N/air_N)*c_p_H2O_units;
end

%% output 
Cp_values = zeros(1,2);
Cp_values(1) = Cp;
Cp_values(2) = Cp_units;

end